<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>计算属性的setter和getter</title>
  </head>
  <body>
    <div id="app">
      <h2>{{fullName}}</h2>
    </div>
    <script src="../vue.js"></script>
    <script>
      const app = new Vue({
        el: "#app",
        data: {
          firstName: "java",
          lastName: "web",
        },
        computed: {
          fullName0: function () {
            return this.firstName + " " + this.lastName;
          },
          //计算方法一般没有set方法，即为只读属性
          fullName: {
            //可以有setter方法
            set: function (newvalue) {
              const names = newvalue.split(" ");
              this.firstName = names[0];
              this.lastName = names[1];
            },

            get: function () {
              return this.firstName + " " + this.lastName;
            },
          },
        },
      });
    </script>
  </body>
</html>
